<?php if (($section == "comments") || ($section == "view_comments")) { ?>
<div id="comment-preview">
<h1><?php echo "Module ".$row_themes['mid'].", Theme ".$row_themes['theme_num'].": ".$row_themes['theme_title']; ?></h1>
<?php echo $row_themes['theme_text']; ?>
</div>
<?php } // end 

else 

{ ?>


<h3>Module <?php echo $row_modules['mid']; ?> Themes</h3>
<?php if ($modal_window != "true") { ?>
<div class="stacked">
<span class="icon"><img src="images/page_add.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?section=proposal_titles&action=add&dbTable=themes&cid=<?php echo $cid; ?>','mid','<?php echo $row_modules['mid']; ?>','Are you sure you want to add a theme to Module <?php echo $row_modules['mid']; ?>?')">Add a Theme to Module <?php echo $row_modules['mid']; ?>?</a>
</div>
<?php } ?>
<table class="dataTable">
	<tr style="background-color: <?php echo $color1; ?>">
        <th class="data" width="10%">#</th>
        <th>Title</th>
        <th class="data" width="10%">ID/Reviewer<br />Comments?</th>
        <th class="data" width="10%">Changes<br />Needed?</th>
        <th class="data" width="10%">Current Version</th>
        <th class="data" width="10%">Other Versions</th>
        <th class="data" width="23%">Actions</th>
    </tr>
	<?php 		
			do { $d[] = $row_themes['theme_num']; } while ($row_themes = mysql_fetch_assoc($themes));
			sort($d);
			foreach (array_unique($d) as $value1) {
				$query_theme_loop = sprintf("SELECT * FROM themes WHERE cid='%s' AND mid='%s' AND theme_num='%s' ORDER BY vid DESC LIMIT 1", $cid, $row_modules['mid'], $value1);
				$theme_loop = mysql_query($query_theme_loop, $connection) or die(mysql_error());
				$row_theme_loop = mysql_fetch_assoc($theme_loop);
				$totalRows_theme_loop = mysql_num_rows($theme_loop);
				
				$query_theme_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='themes' AND rid='%s'", $cid, $row_theme_loop['id']);
				$theme_comments = mysql_query($query_theme_comments, $connection) or die(mysql_error());
				$row_theme_comments = mysql_fetch_assoc($theme_comments);
				$totalRows_theme_comments = mysql_num_rows($theme_comments);
				
				if ($totalRows_theme_loop > 0) { ?>
	<tr style="background-color: <?php echo $color; ?>">
		<td class="data" nowrap="nowrap">Theme <?php echo $row_theme_loop['theme_num']; ?>:</td>
    	<td class="data"><?php if ($row_theme_loop['theme_title'] != "") echo display_content($row_theme_loop['id'],"themes"); else { ?><span class="icon"><img src="images/exclamation.png" border="0" align="absmiddle" /></span>No Title Entered<?php } ?></td>
        <td class="data">
		<?php if ($totalRows_theme_comments > 0) echo "<div class='stacked'><span class='icon'><img src='images/comment.png' align='absmiddle' border='0'></span>Yes - <a id='modal_window_link' href='index.php?section=view_comments&amp;dbTable=themes&amp;cid=".$cid."&amp;id=".$row_theme_loop['id']."&amp;modal_window=true' title='View ID Comments'>View</a></div>"; else echo "<div class='stacked'><span class='icon'><img src='images/comment_fade.png' align='absmiddle' border='0'></span>No</div>"; if ($row_user['userLevel'] <= "2") echo "<div class='stacked'><span class='icon'><img src='images/comment_add.png' align='absmiddle' border='0'></span><a id='modal_window_link' href='index.php?section=comments&action=add&amp;cid=".$cid."&amp;dbTable=themes&amp;id=".$row_theme_loop['id']."&amp;modal_window=true'>Add Comment</a></div>"; ?>
        </td>
        
        <!-- Changes Needed -->
        <td class="data"><?php  if ($row_theme_comments['changes'] == "Y") echo "<span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>Yes"; else echo "<span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span>No";  ?></td>
        
        <!-- Current Versions -->
        <td class="data"><?php if ($row_theme_loop['vid'] != "") echo $row_theme_loop['vid']; else echo "<div class='stacked'><span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>No content</div>"; ?></td>
       
        <!-- Other Versions -->
        <td class="data">
        
        <?php 
		// Get the other versions of the assignment, if any
			$query_versions = sprintf("SELECT * FROM themes WHERE cid='%s' AND mid='%s' AND theme_num='%s' ORDER BY vid", $cid, $row_modules['mid'], $row_theme_loop['theme_num']);
			$versions = mysql_query($query_versions, $connection) or die(mysql_error());
			$row_versions = mysql_fetch_assoc($versions);
			$totalRows_versions = mysql_num_rows($versions);
			//echo $totalRows_assign_versions;
			
			if ($totalRows_versions > 1) {
									do 	{ 
										if (($totalRows_versions > 0) && ($row_versions['vid'] != $row_theme_loop['vid'])) echo "<a id='modal_window_link' href='index.php?section=view_course&amp;action=review&amp;go=theme&amp;cid=".$cid."&amp;id=".$row_versions['id']."&amp;modal_window=true'>".$row_versions['vid']."</a>&nbsp;&nbsp;"; 
										} while ($row_versions = mysql_fetch_assoc($versions));
								} else echo "None";
		?>
        
        </td>
        
        <!-- Actions -->
        <td class="data">
        <?php if ($modal_window != "true") { ?>
        <div class="stacked">
        <span class="icon"><img src="images/page_<?php if ($row_theme_loop['theme_text'] == "") echo "add"; else echo "edit"; ?>.png" border="0" align="absmiddle" /></span><a id="modal_window_link" href="index.php?section=module_theme&amp;action=<?php if ($row_theme_loop['theme_text'] == "") echo "add"; else echo "edit"; ?>&amp;go=<?php if ($row_theme_loop['theme_text'] != "") echo "make-changes"; else echo "draft"; ?>&amp;view=course_detail&amp;dbTable=themes&amp;cid=<?php echo $cid; ?>&amp;mid=<?php echo $row_theme_loop['mid']; ?>&amp;vid=<?php if ($row_theme_loop['vid'] != "") echo $row_theme_loop['vid']; else echo "default"; ?>&amp;id=<?php echo $row_theme_loop['id']; ?>&amp;modal_window=true"><?php if ($row_theme_loop['theme_text'] == "") echo "Add"; else echo "Make Changes to"; ?> Theme Content</a>
        </div>
		<?php if ($row_theme_loop['theme_num'] > "1") { ?>
        <div class="stacked">
        <span class="icon"><img src="images/bin_closed.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?action=delete&dbTable=themes','id','<?php echo $row_themes['id']; ?>','Are you sure want to delete Module <?php echo $row_theme_loop['mid']; ?>, Theme <?php echo $row_theme_loop['theme_num']; ?>?')">Delete Theme</a>
        </div>
		<?php } ?>
        <?php } ?></td>
	</tr>
    <?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
                
                <?php 	
				} // end if ($totalRows_theme_loop > 0)
			} // end foreach (array_unique($d) as $value1)
	?>
</table>
<?php } ?>